package com.liugh.service.queue;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class RedisSend {

    private static final Logger LOGGER = LoggerFactory.getLogger(RedisSend.class);
    private final String channel = "chat";
    private final String downChannel = "download";

    @Autowired
    private RedisTemplate redisTemplate;

    //发送消息
    public boolean sendMessage(String msg) {
        boolean isSuccess = false;
        try {
            redisTemplate.convertAndSend(channel,msg);
            isSuccess = true;
        } catch (Exception e) {
            LOGGER.error("上传申请时发送redis消息出错",e.getMessage());
        }
        return isSuccess;
    }

    //发送下载申请的消息
    public boolean sendDownloadMsg(String msg) {
        boolean isSuccess = false;
        try {
            redisTemplate.convertAndSend(downChannel,msg);
            isSuccess = true;
        } catch (Exception e) {
            LOGGER.error("下载申请时发送redis消息出错",e.getMessage());
        }
        return isSuccess;
    }
}
